<template>
  <div class="search-bar">
    <el-form :inline="true" :model="formItem" class="form-filter" size="mini">
      <el-form-item>
        <treeselect
          v-model="formItem.s_assetTypeCode"
          :multiple="false"
          :options="typeOptions"
          placeholder="选择资产类型"
          @input="search"
        />
      </el-form-item>
      <el-form-item>
        <el-input
          v-model="formItem.s_name"
          size="mini"
          clearable
          placeholder="请输入名称..."
          @keyup.enter.native="search"
          @change="onGlobeSearchInputChange"
        />
      </el-form-item>

      <el-form-item>
        <el-button plain icon="el-icon-search" @click="search" />
        <!-- <el-button plain icon="el-icon-refresh-left" @click="reset">重置</el-button> -->
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { tree } from '@neu/dcam-ui/api/assetType'
// 定义一个查询表单原始项
const formItem = {
  s_name: '',
  s_assetTypeCode: null
}

export default {
  name: 'ReminderTableFilter',
  data() {
    return {
      currentSelectTypeCode: false,
      formItem: { ...formItem },
      /** 资产类型树 */
      typeOptions: []
    }
  },
  created() {
    tree().then(response => {
      const result = response.data
      this.typeOptions = result
    })
  },
  methods: {
    // 查询按钮点击事件处理
    search: function() {
      this.$parent.filter(this.formItem)
    },
    // 重置按钮点击事件处理
    reset: function() {
      this.formItem = { ...formItem }
      this.search()
    },
    onChange: function(val) {
      this.$parent.onResize()
    },
    onGlobeSearchInputChange(value) {
      if (value === '') {
        this.search()
      }
    }
  }
}
</script>
